package com.allwees.support.payment.oceanpay.client;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.simplexml.SimpleXmlConverterFactory;

import java.util.concurrent.TimeUnit;

/**
 * @author Daniel
 * @version 1.0.0
 * @since 2020/12/5 20:55
 */
class RetrofitManager {

    private static final String BASE_URL = "https://query.oceanpayment.com/service/";

    private Retrofit retrofit;

    private RetrofitManager() {
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
//                .addInterceptor(new HeaderInterceptor())
                .connectTimeout(10, TimeUnit.SECONDS)
                .readTimeout(10, TimeUnit.SECONDS)
                .build();

        retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .client(okHttpClient)
                .addConverterFactory(SimpleXmlConverterFactory.create())
                .build();
    }

    private static volatile RetrofitManager retrofitManager = null;

    static RetrofitManager getInstance() {
        if (retrofitManager == null) {
            synchronized (RetrofitManager.class) {
                if (retrofitManager == null) {
                    retrofitManager = new RetrofitManager();
                }
            }
        }
        return retrofitManager;
    }

    Retrofit getRetrofit() {
        return retrofit;
    }
}
